package 差分;/**
 * @author： li
 * @date： 2022-04-04 12:37
 * @version 1.0
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.*;
public class 绝世武功 {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    public static void main(String[] args) throws IOException {
        in.nextToken();
        int n =(int)in.nval;
        in.nextToken();
        int m =(int)in.nval;
        long sum=0;
        long[] a=new long[n+10];
        long[] cf_a=new long[n+10];
        long[] cf_cf_a=new long[n+10];
        while(m>0){
            in.nextToken();int l =(int)in.nval;
            in.nextToken();int r =(int)in.nval;
            in.nextToken();int s =(int)in.nval;
            in.nextToken();int e =(int)in.nval;
            int d=(e-s)/(r-l);
            cf_cf_a[l]+=s;
            cf_cf_a[l+1]+=d-s;
            cf_cf_a[r+1]-=d+e;
            cf_cf_a[r+2]+=e;
            m--;
        }
        for(int i=1;i<=n;i++){
            cf_a[i]=cf_cf_a[i]+cf_a[i-1];//cf_cf_a[i]=cf_a[i]-cf_a[i-1];
            a[i]=cf_a[i]+a[i-1];//cf_a[i]=a[i]-a[i-1];
            sum+=a[i];
        }
//        System.out.println(Arrays.toString(a));
//        System.out.println(Arrays.toString(cf_a));
//        System.out.println(Arrays.toString(cf_cf_a));
        System.out.println(sum);
    }
}
